﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTOSingTowerMall;

namespace BLSingTowerMall
{
    public class VWStoreProcess
    {
        private DBSingTowerMallEntities db = new DBSingTowerMallEntities();

        public List<VWStoreGroup> StoreByLevel(int level)
        {
            var stores = new List<VWStoreGroup>();

            if (level == 0)
            {
                stores = (from s in db.VWStores
                             group s by s.SubCategoryName into g
                             select new VWStoreGroup() { Name = g.Key, Count = g.Count() }).ToList();
            }
            else
            {
                stores = (from s in db.VWStores
                             where s.Level == level
                             group s by s.SubCategoryName into g
                             select new VWStoreGroup() { Name = g.Key, Count = g.Count() }).ToList();
            }
            return stores;
        }

        public IQueryable<IVWStore> GetStoreAndCategory()
        {
            var stores = from s in db.VWStores
                         select s;
            return stores;
        }
    }
}
